package com.yuexun.dhdoctor.module.survey.presenter.impl;


import com.yuexun.dhdoctor.base.BaseEntity;
import com.yuexun.dhdoctor.module.survey.model.ISurveyModel;
import com.yuexun.dhdoctor.module.survey.presenter.IUpdateSurveyPresenter;
import com.yuexun.dhdoctor.module.survey.ui.view.IUpdateSurveyView;

import org.kymjs.kjframe.ui.ViewInject;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by wangt on 2017/8/23.
 */

public class UpdateSurveyPresenter implements IUpdateSurveyPresenter {
    private ISurveyModel model;
    private IUpdateSurveyView view;

    public UpdateSurveyPresenter(ISurveyModel model, IUpdateSurveyView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void updateSurveyAnswer(Map<String, String> praise) {
        model.updateSurveyAnswer(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<BaseEntity<String>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("请检查网络状态");
                    }

                    @Override
                    public void onNext(BaseEntity<String> bean) {
                        view.updateSurvey(bean);
                    }
                });
    }
}
